package com.example.lt.controller;

import com.example.lt.context.BaseContext;
import com.example.lt.pojo.entity.UserSupport;
import com.example.lt.result.Result;
import com.example.lt.service.UserSupportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 小涛Tao
 * @Date: 2024/06/04/14:20
 * version 1.0 注释：
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/userSupport")
public class UserSupportController {

    private final UserSupportService userSupportService;

    /**
     * 检查当前用户是否点赞了当前评论
     * @param userSupport
     * @return
     */
    @PostMapping("/user/check")
    public Result checkSupport(@RequestBody UserSupport userSupport) {
        log.info("检查当前用户是否点赞了当前评论：{}",userSupport);
        return userSupportService.checkSupport(userSupport);
    }

    /**
     * 删除当前用户对当前评论的点赞
     * @param userSupport
     * @return
     */
    @PostMapping("/user/delete")
    public Result delete(@RequestBody UserSupport userSupport) {
        log.info("删除当前用户对当前评论的点赞：{}",userSupport);
        // 把前端传过来的用户id改成token令牌中解析出来的用户id
        userSupport.setUserId(BaseContext.getCurrentId());
        return userSupportService.delete(userSupport);
    }

    /**
     * 添加当前用户对当前评论的点赞
     * @param userSupport
     * @return
     */
    @PostMapping("/user/insert")
    public Result insert(@RequestBody UserSupport userSupport) {
        log.info("添加当前用户对当前评论的点赞：{}",userSupport);
        // 把前端传过来的用户id改成token令牌中解析出来的用户id
        userSupport.setUserId(BaseContext.getCurrentId());
        return userSupportService.insert(userSupport);
    }

}
